package mo.tags.stack;

public class L2211 {

    public int countCollisions(String directions) {
        int n = directions.length();
        int left = 0, right = n - 1;
        int rCount = 0;
        while (left < n) {
            if (directions.charAt(left) == 'L') {
                left++;
            } else {
                break;
            }
        }
        while (right >= 0) {
            if (directions.charAt(right) == 'R') {
                right--;
            } else {
                break;
            }
        }
        for (int i = left; i <= right; i++) {
            if (directions.charAt(i) == 'S') {
                rCount++;
            }
        }
        return right - left + 1 - rCount;

    }

}
